New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add better parser error when using jsx #11722
Conversation
* No {jsx,flow,typescript} plugin * Type parameter * Valid JS Code
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/24295/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 4357684:
|
@@ -0,0 +1 @@ | |||
<div></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add the following test case?
<div>{name}</div>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and done (:
Test parser with no plugins and when jsx is given with a js expression
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
packages/babel-parser/test/fixtures/jsx/errors/_no-plugin-ts-type-param/input.js
Show resolved
Hide resolved
@@ -0,0 +1,4 @@ | |||
{ | |||
"plugins": [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add only jsx
here? I think it will still throw syntax error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does throw that error
SyntaxError: Unexpected token (1:13)
> 1 | <div>() => {}
| ^
What would the correct error message (if any) be in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can throw something like "expected closing JSX element" it's better, otherwise Unexpected token
is ok for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me, pushing that final test
Should we retarget this onto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Added tests to
babel-parser
to check when the<
symbol is used in the following circumstances:"use strict" < div
)This PR also address issue #11499 and adds a
tt.relational
test case inparseExprAtom
.If that test case is triggered then a
expectOnePlugin(["jsx", "flow", "typescript"])
error is thrown.